function GM:SpawnVehicle(ply, pos, ang)
	self:RemoveVehicle(ply, false, false)

	local vehicle = ents.Create("prop_vehicle_jeep_old")

	vehicle:SetPos(pos)
	vehicle:SetAngles(ang)

	vehicle:SetModel("models/buggy.mdl")
	vehicle:SetKeyValue("vehiclescript", "scripts/vehicles/race_base.txt")

	vehicle:Spawn()
	vehicle:Activate()

	vehicle.Params = vehicle:GetVehicleParams()
	PrintTable(vehicle.Params)

	vehicle:SetHealth(2000)
	vehicle:SetMaxHealth(2000)
	
	ply.Vech = vehicle
	vehicle.Ply = ply

	vehicle.SmokeLevel = 0

	umsg.Start("YourCar", ply)
		umsg.Short(vehicle:EntIndex())
	umsg.End()
end

local SmokeTable = {	{3/4, 0.4},
			{1/2, 0.3},
			{1/4, 0.2}}

function GM:VehicleCollision(collidee, instigator, force)
	if !collidee:IsVehicle() then
		collidee, instigator = instigator, collidee
		force = force / 4
	end

	if !collidee.Ply then
		ErrorNoHalt("unknown collidee" .. tostring(collidee) .. "\n")
		return
	end

	local attacker = instigator.Ply or instigator
	local player = collidee.Ply

	if attacker == player || !player.InRace then return end

	player:ChatPrint(tostring(attacker) .. " did " .. tostring(force) .. " damage.")

	local health = collidee:Health()

	health = health - force
	print(health, player)

	if health <= 0 then
		GAMEMODE:RemoveVehicle(player, true, true, attacker)
		return
	end

	local frac = health/collidee:GetMaxHealth()

	for level, tbl in ipairs(SmokeTable) do
		if collidee.SmokeLevel < level && frac < tbl[1] then
			self:SetSmokeLevel(collidee, level, tbl[2])
		end
	end

	collidee:SetHealth(health)
end

function GM:SetSmokeLevel(vehicle, level, color)
	vehicle.SmokeLevel = level

	local effectdata = EffectData()
		effectdata:SetEntity( vehicle )
		effectdata:SetScale( color )
	util.Effect("VehicleSmoke", effectdata)
end

local removing = false

function GM:RemoveVehicle(ply, explode, kill, killer)
	if removing then return end

	removing = true

	if IsValid(ply.Vech) then
		if explode then
			GAMEMODE:VehicleExplode(ply, kill, killer)
		end

		ply.Vech:Remove()
		ply.Vech = nil
	end

	removing = false
end

function GM:VehicleExplode(ply, kill, killer)
	local vehicle = ply.Vech

	if kill then
		ply:ExitVehicle()
		ply:TakeDamage(100, killer or vehicle, vehicle)
		util.BlastDamage(vehicle, killer or vehicle, vehicle:GetPos(), 128, 120)
	end

	local effectdata = EffectData()
		effectdata:SetOrigin( vehicle:LocalToWorld(vehicle:OBBCenter()) )
	util.Effect( "Explosion", effectdata, true, true )
end

// eh.. this hook is in just the right place that I can override the guage
hook.Add("SetupPlayerVisibility", "SetRPM", function(pl)
	if pl:InVehicle() then
		local vehicle = pl:GetVehicle()

		local operate = vehicle:GetOperatingParams()
		local rpm = operate.RPM

		// Careful, red lining in reverse is dangerous!
		if operate.speed < 0 && operate.isTorqueBoosting && pl:KeyDown(IN_BACK) && operate.RPM > vehicle.Params.engine.maxRPM then
			pl:ChatPrint("CHEATER")
			//GAMEMODE:RemoveVehicle(pl, true, true, pl)
		end
		
		vehicle:SetPoseParameter("vehicle_guage", rpm/(vehicle.Params.engine.maxRPM))
	end
end)